import csv

with open('scores.csv', 'r') as file:
    reader = csv.reader(file)
    next(reader)
    data = list(reader)

# print(data)

scores = []

for row in data:py
    # print(row)
    scores.append(int(row[2]))

print(scores)


# for score in scores:
#     print(score)

def calc_mean(scores):
    total = sum(scores)
    count = len(scores)
    mean = total / count
    return mean

def calc_median(scores):
    sorted_scores = sorted(scores)  # 将分数排序
    count = len(sorted_scores)  # 分数数量
    mid = count // 2  # 找到中间位置

    # 如果分数数量是偶数，取中间两个数的平均值；否则取中间的数
    if count % 2 == 0:
        median = (sorted_scores[mid - 1] + sorted_scores[mid]) / 2
    else:
        median = sorted_scores[mid]
    return median

def calc_mode(scores):
    frequency = {}  # 创建一个字典来存储每个分数的频率
    for score in scores:
        if score in frequency:
            frequency[score] += 1  # 如果分数已存在，增加计数
    else:
        frequency[score] = 1  # 如果分数不存在，初始化为1

    max_frequency = max(frequency.values())  # 找到最高频率
    mode = [score for score, freq in frequency.items() if freq == max_frequency]
    return mode

mean = calc_mean(scores)
median = calc_median(scores)
mode = calc_mode(scores)

print(f"The mean is {mean}")
print(f"The median is {median}")
print(f"The mode is {mode}")
